package com.zuhaowan;

import com.github.wxpay.sdk.WXPayConfig;
import com.github.wxpay.sdk.WXPayRequest;
import com.github.wxpay.sdk.WXPayUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class Demo {

    public static void main(String[] args) throws Exception {

//        //1.构建配置对象
//        WxConfig wxConfig = new WxConfig();
//
//        //2.封装请求参数
//        Map map = new HashMap();
//        map.put("appid",wxConfig.getAppID());
//        map.put("mch_id",wxConfig.getMchID());
//        map.put("nonce_str", WXPayUtil.generateNonceStr());
//        map.put("body","消费者下单");
//        map.put("out_trade_no","order110");
//        map.put("total_fee","880");
//        map.put("spbill_create_ip","192.168.55.37");
//        map.put("notify_url","http://pay.zxuhaowan.com/notify");
//
//        //3.将map转成xml
//        String requestMapXml = WXPayUtil.generateSignedXml(map, wxConfig.getKey());
//        //4.发送请求wxpayrequest
//        WXPayRequest request = new WXPayRequest(wxConfig);
//        String responseXml = request.requestWithCert("/pay/unifiedorder", UUID.randomUUID().toString(), requestMapXml, false);
//        System.out.println(responseXml);
//        //5.响应结果生成map集合
//        Map<String, String> responseMap = WXPayUtil.xmlToMap(responseXml);
//        String code_url = responseMap.get("code_url");
//        System.out.println(code_url);


        //查询订单状态
        //1.构建配置对象
        WxConfig wxConfig = new WxConfig();

        //2.封装请求参数
        Map map = new HashMap();
        map.put("appid", wxConfig.getAppID());
        map.put("mch_id", wxConfig.getMchID());
        map.put("nonce_str", WXPayUtil.generateNonceStr());
        map.put("body", "消费者下单");
        map.put("out_trade_no", "order110");
        map.put("total_fee", "880");
        map.put("spbill_create_ip", "192.168.55.37");
        map.put("notify_url", "http://pay.zxuhaowan.com/notify");

        //3.将map转成xml
        String requestMapXml = WXPayUtil.generateSignedXml(map, wxConfig.getKey());
        //4.发送请求wxpayrequest
        WXPayRequest request = new WXPayRequest(wxConfig);
        String responseXml = request.requestWithCert("/pay/orderquery", UUID.randomUUID().toString(), requestMapXml, false);
        System.out.println(responseXml);
        //5.响应结果生成map集合
        Map<String, String> responseMap = WXPayUtil.xmlToMap(responseXml);
        String code_url = responseMap.get("code_url");
    }
}
